package com.sanuo.pico.act.work;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.sanuo.pico.databinding.ActTempBinding;
import com.sanuo.pico.event.Event;
import com.sanuo.pico.event.Temp1;
import com.sanuo.pico.event.TempEvent;
import com.sanuo.pico.it.SettingPage;
import com.sanuo.pico.utils.Command;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class TempAct extends BaseWorkActivity implements SettingPage {

    ActTempBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActTempBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.back.setOnClickListener(v -> Command.sendTouchEvent(0, 0x20));
        setTouch(binding.p1.down, () -> Command.sendTouchEvent(0, 0x78));
        setTouch(binding.p1.up, () -> Command.sendTouchEvent(0, 0x79));
        binding.save.setOnClickListener(v -> Command.sendTouchEvent(0, 0x43));

        onMessageEvent(Event.temp);
        onMessageEvent(Event.temp1);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(TempEvent event) {
        binding.p1.value.setText(event.getValue() + "");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Temp1 event) {
        binding.num1.setText(event.getValue() + "℃");
    }
}
